package Io;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class Exercise {
    public static void main(String[] args) throws IOException {

        File file =new File("test.txt");
        FileInputStream fis=new FileInputStream(file);
        byte[]data =new byte[(int) file.length()];
        fis.read(data);
        String line=new String(data,StandardCharsets.UTF_8);
        System.out.println(line);
        fis.close();


        FileOutputStream fos = new FileOutputStream("test.txt");
        fos.write("我是如此相信，在背后支撑的是你，一直与我并肩而行".getBytes(StandardCharsets.UTF_8));
        System.out.println("写出完毕！");
        fos.close();




        FileInputStream fis3 =new FileInputStream("humansegment_bk2.jpg");
        FileOutputStream fos3 =new FileOutputStream("ooo.jpg");

        long start = System.currentTimeMillis();
        byte[]data1=new byte[1024*10];
        int all;
        while ((all= fis3.read(data1))!=-1){
            fos3.write(data1,0,all);
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕！用时"+(end-start)+"ms");




        FileInputStream fis2 =new FileInputStream("humansegment_bk2.jpg");
        FileOutputStream fos2 =new FileOutputStream("ooo.jpg");
        long start0 = System.currentTimeMillis();

        int o;
        while ((o= fis2.read())!=-1){
            fos2.write(o);
        }
        long end1 = System.currentTimeMillis();
        System.out.println("复制完毕！用时"+(end1-start0)+"ms");

        fis2.close();
        fos2.close();



        FileInputStream fis1=new FileInputStream("ys.dir");
        int q =fis1.read();
        System.out.println(q);
        q =fis1.read();
        System.out.println(q);
        q =fis1.read();
        System.out.println(q);
        fis1.close();


        File file1 = new File("ys.dir");
        FileOutputStream fos1 = new FileOutputStream(file1);
        fos1.write(1);
        fos1.write(255);
        fos1.write(256);
        System.out.println("写出完毕");
        fos1.close();



        /*
        File file =new File("test.txt");
        FileInputStream fis=new FileInputStream(file);
        byte[]data =new byte[(int) file.length()];
        fis.read(data);
        String line=new String(data,StandardCharsets.UTF_8);
        System.out.println(line);
        fis.close();

         */



        /*
        FileOutputStream fos = new FileOutputStream("test.txt");
        String line = "我是如此相信，在背后支撑的是你，一直与我并肩而行";
        byte[]data=line.getBytes(StandardCharsets.UTF_8);
        fos.write(data);
        System.out.println("写出完毕！");
        fos.close();

         */



        /*
        FileInputStream fis =new FileInputStream("humansegment_bk2.jpg");
        FileOutputStream fos =new FileOutputStream("ooo.jpg");

        long start = System.currentTimeMillis();
        byte[]data=new byte[1024*10];
        int all;
        while ((all= fis.read(data))!=-1){
            fos.write(data,0,all);
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕！用时"+(end-start)+"ms");

         */



        /*
        FileInputStream fis =new FileInputStream("humansegment_bk2.jpg");
        FileOutputStream fos =new FileOutputStream("ooo.jpg");
        long start = System.currentTimeMillis();

        int o;
        while ((o= fis.read())!=-1){
            fos.write(o);
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕！用时"+(end-start)+"ms");

        fis.close();
        fos.close();

         */


        /*
        FileInputStream fis=new FileInputStream("ys.dir");
        int o =fis.read();
        System.out.println(o);
        o =fis.read();
        System.out.println(o);
        o =fis.read();
        System.out.println(o);
        fis.close();

         */


        /*
        File file = new File("ys.dir");
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(1);
        fos.write(255);
        fos.write(256);
        System.out.println("写出完毕");
        fos.close();
         */
    }
}
